package cn.earl.springboot.user.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.earl.springboot.entity.User;
import cn.earl.springboot.user.repository.UserRepository;
import cn.earl.springboot.user.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserRepository userRepository;

	@Transactional // 可以使用value指定transactionManager
	@Override
	public void saveUser(User user) {
		userRepository.save(user);

	}

	public User findUserByUsername(String username) {
		return userRepository.findByUsername(username);
	}

	@Override
	public User findUserByUsernameOrPhoneNumberAndPassword(String username, String password) {

		return userRepository.findUserByUsernameOrPhone_numberAndPassword(username, password);
	}

	@Override
	public boolean confirmUserStatus(String username) {
		// TODO Auto-generated method stub
		return userRepository.findStatusByUsername(username);
	}

	@Override
	public User findUserByPhoneNumber(String phone_number) {
		// TODO Auto-generated method stub
		return userRepository.findUserByPhone_number(phone_number);
	}

}
